/*
 * @Author: caiwq caiwq@putron.com
 * @Date: 2022-07-29 10:30:54
 * @LastEditors: caiwq caiwq@putron.com
 * @LastEditTime: 2022-08-01 09:28:12
 * @FilePath: \lmx_web\lmx\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/Layout.vue'
import Login from '@/views/login/index.vue'



Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login,
  },
  {
    path: '/layout',
    name: "Layout",
    component: Layout,
    redirect: '/qiehuan',
    children: [
      {
        path: '/qiehuan',
        name: 'Qiehuan',
        component: () => import('@/components/qiehuan.vue')
      },
      {
        path: '/scene',
        name: 'Scene',
        component: () => import('@/components/scene.vue')
      },
      {
        path: '/setting',
        name: 'Setting',
        component: () => import('@/components/setting.vue')
      }
    ]
  },
]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('lmx_token')
  if (to.name !== 'login' && !token) {
    next({ name: 'login' })
  } else {
    next()
  }
})

export default router
